package exam;

import test01.demo02.userOperation.tools.Const;

import java.sql.*;

public class ConnectionTool {
    public static Connection getDefaultConn() throws SQLException {
        return DriverManager.getConnection(
                test01.demo02.userOperation.tools.Const.URL_TEST,
                test01.demo02.userOperation.tools.Const.USERNAME,
                Const.PASSWORD
        );
    }

    public static void closed(Connection conn, ResultSet rs, PreparedStatement ps){
        closed(conn,ps,null,null);
    }
    public static void closed(Connection conn, Statement sm){
        closed(conn,null,null,sm);
    }
    public static void closed(Connection conn, PreparedStatement ps, ResultSet rs ,Statement sm){
        try {
            if(rs!=null){
                rs.close();
            }
            if(ps!=null){
                ps.close();
            }
            if(conn!=null){
                conn.close();
            }
            if(sm!=null) {
                sm.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
